<?php
/*
简单的加解密类
Created by Reon
@Category	Library
@Library	Rfc
*/
class Rfc
{

	function encode($str){
		$code=@base64_encode($str);
		$len=@strlen($code);
			for($i=0;$i<$len;$i++){
			$nstr.= @chr(@ord(@substr($code,$i,1)) + $i*2%8*3 );
			}
		return str_replace("=","",self::replace(@base64_encode($nstr)));
	}
	
	function decode($str){
		$code=@base64_decode(self::replace($str,true));
		$len=@strlen($code);
			for($i=0;$i<$len;$i++){
			$nstr.= @chr(@ord(@substr($code,$i,1)) - $i*2%8*3 );
			}
		return @base64_decode($nstr);
	}

	function replace($str,$de=false){
		if($de){
			$str=@str_replace("XxX","/",@str_replace("ZzZ","+",$str));
		}else{
			$str=@str_replace("/","XxX",@str_replace("+","ZzZ",$str));
		}
		return $str;
	}

}
?>